package com.kclm.se.enums;

public class UseTrafficLight {

	public static void main(String[] args) throws Exception {
		//
		TrafficLight[] lights = TrafficLight.values();
		//随机设置每种灯的持续时长
		for(TrafficLight light : lights) {
			if(light.equals(TrafficLight.YELLOW)) {
				light.setDuration(3); //黄灯 总是3秒
			} else {
				light.setDuration((int)(Math.random() * 30) + 10);
			}
		}
		//
		TrafficLight temp = TrafficLight.RED;
		while(true) {
			for(int i = temp.getDuration();i > 0;i--) {
				System.out.printf("现在是：%s,倒计时：%d\r", temp, i);
				Thread.sleep(1000);
			}
			//跳到下一个灯
			temp = temp.next();
		}
	}
}
